(function () {
	// 获取合同列表页面数据 服务器分页
	var outId='';
	var serverSchedulingData = {};
	var serverSchedulingTable;
    var serverData = {};
	serverData.key ='';
	serverData.type ='2';
    var	serverTable;
    jQuery(document).ready(function () {
    	serverTable=  jQuery('#allTicketTable').DataTable({
    		"sScrollX": 2000,
			"sScrollXInner": 2000,
			"bScrollCollapse": true,
		    "serverSide": true,
		    "ordering": false,
		    "ajax": {
	            "dataType": "json",
	            "type": "get",
	            "cache": false,
	            "url":window.rootPath+ '/ui/afterSaleOutHouseQuery/getpage',
	            "data": function (d) {
	            	//var outId =d[0].id;
	            	var aaa = $.extend({}, d, serverData);
	            	//outId = aaa[0].id;
	                return $.extend({}, d, serverData);
	            }
	        },
	        "iDisplayLength": 5,
	        columns: [
	            {
	            	data: null,
	            	defaultContent: ""
	            },
	            /*{
	            	data: 'id',
	            	render:function(data,type,full,meta){
						return '<font title="'+data+'" style="display:none">'+data + '</font>';
					}
	            },*/
	            /*{
	                data: null,
	                defaultContent: "",
	                render: function (data, type, full, meta) {
	                    var operate =' <input type="checkbox" class="checkchild" />';
	                    return operate;
	
	                }
	            },*/
	            {
	                data: 'afterSaleTicket.manageCode'
	            },
	            {
	                data: 'createTime',
	                render: function (data, type, full, meta) {
	                    if (data)
	                        return moment(data).format('YYYY/MM/DD');
	                    else
	                        return '';
	               }
	            },
	            {
	                data: 'sendReason',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 5) ? '<font title="'+data+'">'+data.substring(0,5)+'...'+'</font>' : data;
						}
					}
	            },
	            {
	                data: 'afterSaleTicket.unitName',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 5) ? '<font title="'+data+'">'+data.substring(0,5)+'...'+'</font>' : data;
						}
					}
	            },
	            {
	                data: 'afterSaleTicket.contractCode',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 5) ? '<font title="'+data+'">'+data.substring(0,5)+'...'+'</font>' : data;
						}
					}
	            },
	            {
	            	data:'afterSaleTicket.afterSaleType'
	            },
	            {
	            	data:'afterSaleTicket.proposer'
	            },
	            /*{
	            	data:'afterSaleTicket.user.name'
	            },*/
	            {
	            	data:'afterSaleTicket.superior'
	            },
	            {
	            	data:'afterSaleTicket.linkMan'
	            },
	            {
	            	data:'afterSaleTicket.linkManPhone'
	            },
	         
	            {
	            	data:'afterSaleTicket.deviceCode'
	            },
	            {
	            	data:'afterSaleTicket.deviceName',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 5) ? '<font title="'+data+'">'+data.substring(0,5)+'...'+'</font>' : data;
						}
					}
	            },
	            {
	            	data:'afterSaleTicket.deviceNumber'
	            },
	            {
	            	data: 'afterSaleTicket.questionDetail',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 5) ? '<font title="'+data+'">'+data.substring(0,5)+'...'+'</font>' : data;
						}
					}
	            },
	            {
	            	data: 'afterSaleTicket.questionTrance',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 5) ? '<font title="'+data+'">'+data.substring(0,5)+'...'+'</font>' : data;
						}
					}
	            }
	            ],
	        "drawCallback": function (oSettings) {
	            var k = 0;
	            var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;
	            for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
	                $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
	                /*if(k == 0){
	                	outId = oSettings.aoData[oSettings.aiDisplay[k]].nTr;
					}*/
	                k++;
	            }
	        }
	        
	    });
    });
    $('#allTicketTable tbody').on('dblclick','tr',function(){ 
    	var index = $(this).context._DT_RowIndex;//行号
    	var table=getTableData("#allTicketTable",1);
    	outId = table[index].id;
    	serverSchedulingData.outId=outId;
    	serverSchedulingTable.draw();
	});

	jQuery(document).ready(function(){
		serverSchedulingData.outId=outId;
		serverSchedulingTable = jQuery('#ticketTranceTable').DataTable({
		    "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/afterSaleOutHouseQuery/getTrancePage',
                "data": function (d) {
                    return $.extend({}, d, serverSchedulingData);
                }
            },
            "iDisplayLength": 5,
			columns : [
					{
						data : null,
						defaultContent : ""
					},
					{
						data: "activeType",
					},
					{
						data: "user.name",
					},
					{
						data : 'createTime',
						render : function(data,
								type, full,
								meta) {
							if (data) {
								return moment(data).format("YYYY-MM-DD");
							}
						}
					},
					{
						data : 'memo'
					}],
			"drawCallback" : function(oSettings) {
				var k = 0;
				var total = oSettings.aiDisplay.length+ oSettings._iDisplayStart;

				for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
					$('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
					k++;
				}
			}
		});
	});
    	
        
	// 查看计划
	jQuery('#seeSchedulingBtn').on('click', function () {
		var selects=getSelect("#SchedulingTable",1);
		if(selects.length>1){
			$.springLemonDialog({
				content: '只能查看一条计划任务',// 确认文本
				clickButton: function (sender, modal, index) {// 按钮事件处理
					$(this).closeDialog(modal);
				}
			}); 
		}
		else if(selects.length==0){
			$.springLemonDialog({
				content: '请选择要查看的计划任务',// 确认文本
				clickButton: function (sender, modal, index) {// 按钮事件处理
					$(this).closeDialog(modal);
				}
			}); 
		}else if(selects.length==1){
			var cstate = selects[0].cState;
			var userId = jQuery('#userId').val();
			var id=selects[0].id;
			var url=window.rootPath+"/ui/scheduling/schedulingEdit/"+ id + "/see";
			window.location.href = url;
		}
	});
    
    // 计划任务列表中的查询
    $(".searchBtn1").click(function(){
    	var key = jQuery('#keyword1').val();
    	serverSchedulingData.key = key;
    	serverSchedulingTable.draw();
	});
    $(".resetBtn1").click(function(){
    	jQuery('#keyword1').val("");
    	serverSchedulingData.key = "";
    	serverSchedulingTable.draw();
    });
    
    jQuery('#type').change(function(){
    	serverData.key=jQuery("#keyword").val();
    	var type=jQuery('#type').val();
    	serverData.type=type;
    	serverTable.draw();
    	serverSchedulingData.outId="";
		serverSchedulingTable.draw();
	});
    // 合同列表中的查询
    $(".searchBtn").click(function(){
    	var key = jQuery('#keyword').val();
    	var type = jQuery('#type').val();
    	serverData.key = key;
    	serverData.type = type;
    	serverTable.draw();
    	serverSchedulingData.outId="";
		serverSchedulingTable.draw();
    });
    $(".resetBtn").click(function(){
    	jQuery('#keyword').val("");
    	jQuery('#type').val("2");
    	serverData.key = "";
    	serverData.type = "2";
    	serverTable.draw();
    	serverSchedulingData.outId="";
		serverSchedulingTable.draw();
    }); 
})();